#ifndef _DETU_MEDIA_VPSS_GRP_IMP_H_
#define _DETU_MEDIA_VPSS_GRP_IMP_H_

#include "vpss_grp.h"
#include "vpss_chn_imp.h"
#include "vpss_pipe_imp.h"
#include "mutex.h"

#include "hi_common.h"
#include "hi_comm_vpss.h"

#include <map>

namespace detu_media
{

class VpssMgrImp;

class VpssGrpImp : public VpssGrp
{
protected:
    VpssGrpImp(void);

    virtual ~VpssGrpImp(void);

	friend class VpssMgrImp;

public:
    virtual S_Result start(void);

    virtual S_Result stop(void);

    virtual bool isStarted(void);

    virtual S_Result getChn(const std::string& name, VpssChn** ppVpssChn);

    virtual S_Result getPipe(const std::string& name, VpssPipe** ppVpssPipe);

    virtual S_Result getId(int &id);

private:
    S_Result init(const Json::Value& config);

    S_Result deInit(void);

    bool isInited(void);

	S_Result initPipe(const Json::Value& config);

	S_Result deInitPipe(void);

	S_Result initChn(const Json::Value& config);

	S_Result deInitChn(void);

    S_Result startPipe(void);

    S_Result stopPipe(void);

	static S_Result callbackAll(const void* clientData, const std::string& name, const Json::Value& oldConfig, const Json::Value& newConfig, Json::Value& response);

	S_Result callback(const void* clientData, const std::string& name, const Json::Value& oldConfig, const Json::Value& newConfig, Json::Value& response);

	S_Result setGrpAttr(const Json::Value& oldConfig, const Json::Value& newConfig);


private:
	constexpr static const VPSS_GRP_ATTR_S defaultGrpAttr =
	{
	    .u32MaxW 					= 3968,
		.u32MaxH 					= 2768,
		.enPixelFormat 				= PIXEL_FORMAT_YVU_SEMIPLANAR_420,
		.enDynamicRange 			= DYNAMIC_RANGE_SDR8,
		.stFrameRate 				=
			{
				.s32SrcFrameRate 	= -1,
				.s32DstFrameRate 	= -1
			},
		.bNrEn 						= HI_FALSE,
		.stNrAttr 					=
			{
				.enCompressMode 	= COMPRESS_MODE_NONE,//COMPRESS_MODE_SEG,
				.enNrMotionMode 	= NR_MOTION_MODE_NORMAL
			}
	};

private:
    typedef std::map<const std::string, VpssChnImp*>   ChnMap;
    typedef std::map<const std::string, VpssPipeImp*>  PipeMap;

    ChnMap                  	fChnMap;
    PipeMap                 	fPipeMap;

    VPSS_GRP                    fGrpId;
    VPSS_GRP_ATTR_S             fGrpAttr;

    int                         fRef;
    bool                        fInited;

	detu_infra::Mutex           fMutex;
};

}

#endif
